#include "StdAfx.h"
#include "dll_object.h"
#include "wnd_capture_ex_impl.h"
#include <utility/api_tools.h>
#include <interface/interface.h>
#include <interface/log_interface.h>
#include <interface/wnd_capture_ex_interface.h>

#pragma warning(disable:4996)

aot::tt::imain*		dll_object::im_ = NULL;
dll_object* g_dll_obj = NULL;

dll_object::dll_object()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	this->im_ = NULL;
	this->ptr_wnd_capture_ex_ = NULL;
}

dll_object::~dll_object()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	if( this->ptr_wnd_capture_ex_ )
	{
 		delete this->ptr_wnd_capture_ex_;
 		this->ptr_wnd_capture_ex_ = NULL;
	}
}

void 
dll_object::destroy()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	if( 0 == dec_ref() )
	{
		delete this;
	}
}


bool 
dll_object::on_regist(aot::tt::idll::dll_regist_param_t* p, aot::tt::result_t* ret)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	this->im_ = p->mi;
	this->i_wrapper_.init_component_query(this->im_, this);

	return true;
}

bool 
dll_object::query_interface(void** out, const char* key)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	if ( 0 == strcmp("iwnd_capture_ex", key) )
	{
		if( NULL == this->ptr_wnd_capture_ex_ )
		{
			this->ptr_wnd_capture_ex_ = new wnd_capture_ex_impl;/// handled del
		}

 		*out = this->ptr_wnd_capture_ex_;

		return true;
	}

	return false;
}

/// basic check by fan05